<template>
    <div class="panel-body panel-home">
        <div class="panel-header">
            <div class="panel-title">
                {{ meta_name }}
            </div>
        </div>
        <div class="panel-main">
            <div class="panel-btns">
                <el-button type="success" icon="fa fa-refresh" @click="list()" size="small"> 刷新</el-button>
            </div>
            <div class="panel-search">
                <div class="panel-search-item">
                    <el-input  size="medium" v-model="params.kwd" clearable placeholder="请输入就诊人名称" style="width: 250px" class="input-with-select">
                        <el-button type="primary" @click="search()" slot="append" icon="el-icon-search"></el-button>
                    </el-input>
                </div>
                <div class="panel-search-item">
                    <el-input  size="medium" v-model="params.mobile" clearable placeholder="请输入用户手机号" style="width: 180px" class="input-with-select"></el-input>
                </div>
                <div class="panel-search-item">
                    <el-input  size="medium" v-model="params.uid" clearable placeholder="请输入用户ID" style="width: 150px" class="input-with-select"></el-input>
                </div>
            </div>
            <el-table v-loading="loading"
                      element-loading-text="努力加载中..."
                      element-loading-spinner="el-icon-loading"
                      ref="multipleHandle"
                      tooltip-effect="dark"
                      :data="listData.data" border>
                <el-table-column align="center" prop="id" label="编号" width="70"></el-table-column>
                <el-table-column prop="username" label="就诊人" width="100"></el-table-column>
                <el-table-column align="center" prop="sex_text" label="性别" width="50"></el-table-column>
                <el-table-column align="center" prop="mobile" label="电话" width="115"></el-table-column>
                <el-table-column align="center" prop="height" label="身高" width="80">
                    <template slot-scope="scope">
                        {{scope.row.height}}cm
                    </template>
                </el-table-column>
                <el-table-column align="center" prop="weight" label="体重" width="80">
                    <template slot-scope="scope">
                        {{scope.row.weight}}kg
                    </template>
                </el-table-column>
                <el-table-column align="center" prop="age" label="年龄" width="50"></el-table-column>
                <el-table-column align="center" prop="group.name" label="分组" width="100"></el-table-column>
                <el-table-column align="center" prop="user.username" label="用户名" width="120">
                    <template slot-scope="scope">
                        <el-button @click="user(scope.row.user.id)" type="text">{{ scope.row.user.username }}</el-button>
                    </template>
                </el-table-column>
                <el-table-column  prop="created_at" label="注册日期" width="160">
                    <template slot-scope="scope">
                        {{moment(scope.row.created_at).format('YYYY-MM-DD HH:mm:ss')}}
                    </template>
                </el-table-column>
                <el-table-column  prop="updated_at" label="更新日期">
                    <template slot-scope="scope">
                        {{moment(scope.row.updated_at).format('YYYY-MM-DD HH:mm:ss')}}
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination"  v-if="!loading && listData && listData.total">
                <div class="pagination-total">共 <em> {{listData.total}} </em> 条记录</div>
                <el-pagination v-if="listData.last_page > 1"
                               background
                               :page-size="listData.per_page"
                               layout="prev, pager, next, jumper"
                               :total="listData.total"
                               prev-text="上一页"
                               next-text="下一页"
                               :current-page="listData.current_page"
                               @current-change="changePage">
                </el-pagination>
            </div>
        </div>
    </div>
</template>
<!---->
<script>
    import {mapGetters} from 'vuex';
    import {MemberList} from '@/utils/request';
    export default {
        computed: {
            ...mapGetters(['meta_name','loading']),
        },
        data() {
            return {
                listData: [],//列表数据
                params: {page: 1, kwd: '', mobile: '',uid:''},
            }
        },
        activated() {
            if(this.$route.query.id){
                this.params.uid = this.$route.query.id;
            }else{
                this.params.uid = '';
            }
            this.list();
        },
        methods: {
            //积分
            user(id){
                this.$router.push({name:'User',query:{id:id}});
            },
            //列表
            list(){
                this.$store.dispatch('setLoading', true);
                MemberList({params: this.params}).then((res)=>{
                    if (res.code) {
                        this.$notify.error({title: 'ERROR', message: res.msg});
                    } else {
                        this.listData = res.data;
                    }
                    this.$store.dispatch('setLoading', false);
                })
            },
            //筛选
            search(){
                this.params.page = 1;
                this.list();
            },
            //分页
            changePage(val) {
                this.params.page = val;
                this.list();
            }
        }
    }
</script>
